package com.sky.action;

import com.sky.model.BaseModel;
import com.sky.model.User;
import com.sky.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserAction {

    @Autowired
    UserService userService;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(User user) throws IOException {
        Map<String,Object> result = new HashMap<>();
        List<BaseModel> oResult = userService.query(user);
        result.put("records",oResult);
        return result;
    }

    @RequestMapping("login")
    @ResponseBody
    public Map<String,Object> login(@RequestParam String username, @RequestParam String password) throws IOException {
        Map<String,Object> result = new HashMap<>();
        boolean oResult = this.userService.login(username,password);
        result.put("record",oResult);
        return result;
    }
}
